package homework.test2;

public class StudentsTool {
    //遍历打印学生信息
    public void listStudents(Student[] arr) {
        for (Student student : arr) {
            System.out.println(student);
        }
    }
    //获取学生成绩的最高分
    public double getMaxScore(Student[] arr) {
        //定义最高分索引
        int maxIndex = 0;
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i].getScore() > arr[maxIndex].getScore()){
                maxIndex = i;
            }
        }
        return arr[maxIndex].getScore();
    }
    //获取成绩最高的学员
    public Student getMaxStudent(Student[] arr){
        int maxIndex = 0;
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i].getScore() > arr[maxIndex].getScore()){
                maxIndex = i;
            }
        }
        return arr[maxIndex];
    }
    //获取学生成绩的平均值
    public int getAverageScore(Student[] arr){
        //定义变量保存总分
        int sum = 0;
        for (Student student : arr) {
            sum += student.getScore();
        }
        return sum/arr.length;
    }
    //获取不及格的学员数量
    public int getCount(Student[] arr){
        //定义变量保存不及格人数
        int count = 0;
        for (Student student : arr) {
            if (student.getScore() < 60){
                count++;
            }
        }
        return count;
    }
}
